home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / SCRDEMO.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  6.7 KB  |  136 lines

  1. ;
  2. ;       Program ScrDemo ( Chapter 11 )
  3. ;
  4.     page    55,132
  5. NewFunc equ     0E0h
  6. CheckIn equ     0                       ; subfunction "check installation"
  7. InAct   equ     0                       ; this value indicates "INACTIVE"
  8. Act     equ     1Ch                     ; this value indicate "ACTIVE"
  9.  
  10. _Text   segment para public 'CODE'
  11.     assume  cs:_Text
  12. ;====================  Resident data =====================================      
  13. ActInd  db      Act                     ; activity indicator; if 0 - inactive
  14. NumTick dw      0                       ; number of timer ticks since last key
  15. MaxTick equ     546 ; 5460                      ; 5460 ticks = 5 minutes
  16. BlankId db      0                       ; screen blank indicator; if 0 - not blankedA
  17. Blanked equ     13h                     ; signature "screen is blanked"
  18. ;=====================  Resident code ====================================
  19. NewInt9 proc    near                    ; additional handler for interrupt 09h
  20.     mov     NumTick,0               ; key pressed - clear ticks counter
  21.     cmp     BlankId,Blanked         ; is screen blanked?
  22.     jne     ToOld9                  ; if not - nothing to do
  23.     mov     BlankId,0               ; clear blank indicator
  24. ;===    Save register used      
  25.     mov     SaveAX9,ax
  26.     mov     SaveBX9,bx
  27. ;---    Restore VGA screen
  28.     mov     ax,1200h                ; function 12h - set alternate function
  29.     mov     bl,36h                  ; subfunction 32h - Enable/Disable refresh
  30.     int     10h                     ; BIOS video service call
  31. ;===    Restore registers
  32.     mov     bx,SaveBX9
  33.     mov     bx,SaveBX9
  34. ;===    Pass the control to the standard handler of the interrupt 09h   
  35. ToOld9:
  36.     db      0EAh                    ; this is code for JMP FAR
  37. OldOff9 dw      0                       ; here will be ofsset
  38. OldSeg9 dw      0                       ; here will be segment
  39. SaveAX9 dw      ?
  40. SaveBX9 dw      ?
  41. NewInt9 endp
  42. ;===
  43. Handler proc    near                    ; additional handler for interrupt 1Ch
  44.     cmp     ah,NewFunc              ; additional function of INT 1Ch?
  45.     je      Addf                    ; new handler for that function
  46.     cmp     ActInd,Act              ; is activity indicator set?
  47.     je      Process                 ; if so, continue work
  48.     jmp     ToOld1C                 ; if not, pass control to old handler
  49. ;===    Check whether the screen is already blanked
  50. Process:cmp     BlankId,Blanked         ; is screen blanked?
  51.     je      ToOld1C                 ; if so - nothing to do
  52. ;===    Has the time gone?
  53.     inc     NumTick                 ; increase ticks counter
  54.     cmp     NumTick,MaxTick         ; is it time to blank screen
  55.     jl      ToOld1C                 ; if not, procced to standard handler
  56. ;===    Blank the screen        
  57.     mov     BlankId,Blanked         ; set blank indicator
  58.     mov     NumTick,0               ; clear ticks counter
  59. ;---    save registers
  60.     mov     SaveAXC,ax
  61.     mov     SaveBXC,bx
  62. ;---    Blank VGA screen        
  63.     mov     ax,1201h                ; function 12h - set alternate function
  64.     mov     bl,36h                  ; subfunction 32h - Enable/Disable refresh
  65.     int     10h                     ; BIOS video service call
  66. ;---    Restore registers       
  67.     mov     bx,SaveBXC
  68.     mov     ax,SaveAXC
  69. ;===    Pass the control to the standard handler of the interrupt 1Ch   
  70. ToOld1C:
  71.     db      0EAh                    ; this is code for JMP FAR
  72. OldOffC dw      0                       ; here will be ofsset
  73. OldSegC dw      0                       ; here will be segment
  74. ;===    Process additional function of interrupt 1Ch
  75. Addf:   mov     ah,CheckIn              ; value to be returned into AH
  76.     mov     al,NewFunc
  77.     iret                            ; return from handler   
  78. SaveAXC dw      ?
  79. SaveBXC dw      ?
  80.     
  81. Handler endp
  82. ;===    Installation part of the program
  83. Start:  push    cs
  84.     pop     ds                      ; DS = CS - data and code are the same 
  85. ;===    check whether the program is alrady installed
  86.     mov     ah,NewFunc              ; new funtion of INT 1Ch
  87.     mov     al,CheckIn              ; AL - installation check
  88.     int     1Ch                     ; call interrupt 1Ch - timer tick
  89.     cmp     ah,Checkin              ; does AH contain function number?
  90.     je      Already                 ; if YES, handler is already installed
  91. ;===    installation part       
  92. Install:mov     ax,351Ch                ; function 35h - Get Interrupt Vector
  93.     int     21h                     ; DOS service call
  94.     mov     cs:OldOffC,bx           ; save offsett of old handler for 1Ch
  95.     mov     cs:OldSegC,es           ; save segment of old handler for 1Ch
  96.     mov     al,09h                  ; AL - interrupt number, AH keeps 35h
  97.     int     21h                     ; DOS service call
  98.     mov     cs:OldOff9,bx           ; save offsett of old handler for 09h
  99.     mov     cs:OldSeg9,es           ; save segment of old handler for 09h
  100.     cli                             ; caution! critical part of program
  101.     mov     dx,offset Handler       ; address of handler
  102.     mov     ax,251Ch                ; function 25h - Set new handler
  103.     int     21h                     ; DOS service call
  104.     mov     dx,offset NewInt9       ; address of new INT 09 handler
  105.     mov     al,09h                  ; AL - interrupt number, AH keeps 25h
  106.     int     21h                     ; DOS service call
  107.     sti                             ; critical part finishes here
  108. ;===    output the message "program is installed"
  109.     mov     ActInd,Act              ; set activity indicator (TSR "ON")
  110.     lea     dx,BegMsg               ; DX - address of message
  111.     mov     ah,09h                  ; function 09 - output string
  112.     int     21h                     ; DOS service call
  113. ;===    calculate the size of the resident part 
  114.     lea     dx,INSTALL
  115.     add     dx,110h                 ; PSP length plus 16 byte (insurance) 
  116.     mov     cx,4                    ; set counter for shift
  117.     shr     dx,cl                   ; 4 bits to the right - divide by 16
  118.     mov     ax,3100h                ; 31h - terminate and state resident
  119.     int     21h                     ; DOS service call
  120. ;===    Process situation "Resident part is already installed"
  121. Already:mov     ah,09h                  ; function 09 - output text string
  122.     lea     dx,AlrMsg               ; DS:DX - address of initial message
  123.     int     21h                     ; DOS service call
  124. ;===    Exit program    
  125.     mov     ax,4C01h                ; function 4Ch - terminate process
  126.     int     21h                     ; DOS service call
  127. ;===    Data for non-resident part of the program
  128. CR      equ     0Ah
  129. LF      equ     0Dh
  130. EndMsg  equ     24h
  131. BegMsg  db      CR,LF,'Resident screen blanker - demo version '
  132. CRLF    db      CR,LF,EndMsg
  133. AlrMsg  db      CR,LF,'Error - program is already installed',CR,LF,EndMsg
  134. _text   ends
  135.     end     Start
  136.